# 代码实现二分查找

def binarySearch(nums, findNum):
    left, right = 0, len(nums)
    while right >= left:
        mid = int((left + right) / 2)
        if nums[mid] > findNum:
            right = mid - 1
        if nums[mid] < findNum:
            left = mid + 1
        if nums[mid] == findNum:
            return mid


# 冒泡排序
def bubbleSort(arr):
    temp = 0
    flag = False
    for i in range(len(arr)):
        for j in range(len(arr) - i):
            if arr[j] > arr[j + 1]:
                flag = True
                temp = arr[j]
                arr[j] = arr[j + 1]
                arr[j + 1] = temp
        if flag:
            flag = False
        else:
            break


nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
index = binarySearch(nums, 11)
print(index.__str__())
